/*
 * @Author: 晴鸢. 3013433857@qq.com
 * @Date: 2025-08-31 10:49:05
 * @LastEditors: 晴鸢. 3013433857@qq.com
 * @LastEditTime: 2025-08-31 16:14:57
 * @FilePath: /Learn/sharemem/processb.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * @Author: 晴鸢. 3013433857@qq.com
 * @Date: 2025-08-31 10:49:05
 * @LastEditors: 晴鸢. 3013433857@qq.com
 * @LastEditTime: 2025-08-31 13:58:28
 * @FilePath: /Learn/sharemem/processb.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include"common.hpp"
int main()
{
    //创建共享内存
    int shmid=GetShm();
    //挂接当前进程与共享内存
    char*shmaddr=(char*)shmat(shmid,nullptr,0);
    //一旦连接共享内存，该进程可直接使用共享进程
    int fd=open(FIFO_FILE,O_WRONLY);
    if(fd<0)
    {
        log(Fatal,"server error.error string:%s, error code:%d\n",strerror(errno),errno);
        exit(FIFO_OPEN_ERR);
    }
    while(1)
   {
        cout<<"Please Enter@ ";
        fgets(shmaddr,size,stdin);
        write(fd,"c",1);//通知读方我已经写完
   }
    
    //分离当前进程与共享内存
    shmdt(shmaddr);
    close(fd);
    return 0;
}
